/**
 * xxx 模型
 */

'use strict';

var mongoose = require('../mongo_conn.js');
var Schema = mongoose.Schema;

// create a schema
var ModelSchema = new Schema({
	name: {
		type: String,
		require: true,
		unique: true,
		index: true
	},
	code: {
		type: Number,
		require: true,
		unique: true,
		index: true,
		default: 0
	},
	description: String,
	createdAt: {
		type: Date,
		default: Date.now
	},
	updatedAt: {
		type: Date,
		default: Date.now
	}
});

ModelSchema.pre('save', function(next) {
	if (!this.createdAt) {
		this.createdAt = new Date();
	}
	next();
});


// 指定collection name，默认是复数
var permission = mongoose.model('permission', ModelSchema, 'permission');
exports = module.exports = permission;